package model.student;


import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Result;

import myutil.Connect;

import vo.DocumentListVo;
import vo.mixed.CourseListVo;

public class StudentCourseMo {

	ArrayList<CourseListVo> list = new ArrayList<CourseListVo>();
	ArrayList<DocumentListVo>doclist = new ArrayList<DocumentListVo>();
	ArrayList<DocumentListVo>courselist=new ArrayList<DocumentListVo>();
public ArrayList<CourseListVo> getCourseDetails() {
		
		HttpSession session;
		session = ServletActionContext.getRequest().getSession();
		int id=(int) session.getAttribute("user_id");
		String query;
		query="select cd.course_id,course_name, course_code,duration,credit,lab,theory  FROM student_course sc, course_details cd, degree_course dc WHERE sc.student_id="+id+" AND sc.degree_course_id = dc.degree_course_id AND dc.course_id = cd.course_id AND sc.status='running'";
		System.out.println(query);
		Connect c=new Connect();
		try {
			ResultSet rs=c.getResult(query);
			while(rs.next()){
				CourseListVo vo=new CourseListVo();
				vo.setCourse_id(rs.getInt("course_id"));
				vo.setCourse_name(rs.getString("course_name"));
				vo.setCourse_code(rs.getString("course_code"));
				vo.setDuration(rs.getInt("duration"));
				vo.setCredit(rs.getInt("credit"));
				vo.setLab(rs.getInt("lab"));
				vo.setTheory(rs.getInt("theory"));
				list.add(vo);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	return list;	
	}

public ArrayList<CourseListVo> getSemDetails() {
	
	HttpSession session;
	session = ServletActionContext.getRequest().getSession();
	int id=(int) session.getAttribute("user_id");
	String query;
	query="";
	System.out.println(query);
	Connect c=new Connect();
	try {
		ResultSet rs= c.getResult(query);
		while(rs.next()){
			CourseListVo vo=new CourseListVo();
		}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	return list;
	}

	public ArrayList<DocumentListVo> getCourseDocumentList(int course_id)	{
	
		HttpSession session;
		session = ServletActionContext.getRequest().getSession();
		int id=(int) session.getAttribute("user_id");
		String query; 
		int course_professor_id=0;
		query="select course_professor_id from student_batch sb,course_professor cp where sb.student_id="+id+" and sb.batch_id=cp.batch_id";
		System.out.println(query);
		Connect c=new Connect();
		try {
			ResultSet rs= c.getResult(query);
			while(rs.next()){
				course_professor_id=rs.getInt("course_professor_id");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		query="SELECT du.document_id,subject, document_name, upload_date,comment FROM course_document cd, document_upload du WHERE course_professor_id ="+course_professor_id + " AND cd.document_id = du.document_id" ;
		System.out.println(query);
		try {
		ResultSet rs=c.getResult(query);
		while(rs.next())
		{
			int attachment_id,attachment_count=0;String document_name;
			DocumentListVo vo=new DocumentListVo();
			vo.setSubject(rs.getString("subject"));
			document_name=rs.getString("document_name");
			vo.setUpload_date(rs.getInt("upload_date"));
			vo.setComment(rs.getString("comment"));
			attachment_id=rs.getInt("document_id");
			vo.setAttachment_count(attachment_count);
			vo.setDocument_name(document_name);
			vo.setCourse_professor_id(course_professor_id);
			vo.setAttachment_id(attachment_id);
			//read.add(vo);
			doclist.add(vo);
		}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}


		
		
		return doclist;
	}
	
	
	public ArrayList<DocumentListVo> getCourseDetails(int course_id){
		HttpSession session;
		session = ServletActionContext.getRequest().getSession();
		int id=(int) session.getAttribute("user_id");
		String query; 
		int course_professor_id=0;
		query="select course_professor_id from student_batch sb,course_professor cp where sb.student_id="+id+" and sb.batch_id=cp.batch_id";
		System.out.println(query);
		Connect c=new Connect();
		try {
			ResultSet rs= c.getResult(query);
			while(rs.next()){
				course_professor_id=rs.getInt("course_professor_id");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("id is in :"+course_id);
		query="SELECT staff_name,course_name, course_code, lecture_duration, department_name, batch_name FROM course_professor cp, course_details cd, department_details dd, batch_details bd,college_staff cs WHERE course_professor_id ="+ course_professor_id+" AND cp.course_id = cd.course_id AND bd.batch_id = cp.batch_id AND cd.department_id = dd.department_id AND cp.professor_id_1 = cs.staff_id" ;
		System.out.println(query);
		ResultSet rs;
		try {
			rs = c.getResult(query);
			while(rs.next()){
				DocumentListVo vo=new DocumentListVo();
				vo.setCourse_name(rs.getString("course_name"));
				vo.setCourse_code(rs.getString("course_code"));
				vo.setLecture_duration(rs.getInt("lecture_duration"));
				vo.setDepartment_name(rs.getString("department_name"));
				vo.setBatch_name(rs.getString("batch_name"));
				vo.setCourse_professor_id(course_professor_id);
				vo.setStaff_name(rs.getString("staff_name"));
				courselist.add(vo);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return courselist;
	
	}

}
